package com.itheima.flow;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducerTask extends Reducer<Text,FlowPojo,Text, NullWritable> {
    @Override
    protected void reduce(Text key, Iterable<FlowPojo> values, Context context) throws IOException, InterruptedException {

        long upPackNumCount=0;
        long downPackNumCount=0;
        long upPayLoadCount=0;
        long downPayLoad=0;
        for(FlowPojo value:values){
            upPackNumCount+=value.getUpPackNum();
            downPackNumCount+=value.getDownPackNum();
            upPayLoadCount+=value.getUpPayLoad();
            downPayLoad+=value.getDownPayLoad();
        }
        Text text = new Text(key.toString() + "\t" + upPackNumCount + "\t" + downPackNumCount + "\t" + upPayLoadCount + "\t" + downPayLoad);
        context.write(text,NullWritable.get());

        /*Text text = new Text(upPackNumCount + "\t" + downPackNumCount + "\t" + upPayLoadCount + "\t" + downPayLoad);
        context.write(key,text);*/
    }
}
